package com.farben.activiti.domain.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.farben.common.core.domain.BaseEntity;
import lombok.*;
import org.activiti.api.task.model.Task;

import org.activiti.engine.runtime.ProcessInstance;

import java.util.Date;

@EqualsAndHashCode(callSuper = true)
@Data
@With
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ActTaskDTO extends BaseEntity {

    private static final long serialVersionUID = 1L;

    private String id;

    private String name;

    private String status;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createdDate;
    private String instanceName;
    private String definitionKey;
    private String businessKey;

    public ActTaskDTO(Task task, ProcessInstance processInstance) {
        this.id = task.getId();
        this.name = task.getName();
        this.status = task.getStatus().toString();
        this.createdDate = task.getCreatedDate();
        this.instanceName = processInstance.getName();
        this.definitionKey = processInstance.getProcessDefinitionKey();
        this.businessKey = processInstance.getBusinessKey();
    }

}
